package io.gitee.twoke.generator.engine;


import io.gitee.twoke.generator.engine.impl.cfg.StandaloneGenerateEngineConfiguration;
import io.gitee.twoke.generator.engine.impl.runtime.Clock;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.sql.DataSource;

@Getter
@Setter
@Accessors(chain = true)
public abstract class GenerateEngineConfiguration {
    public static final String DB_SCHEMA_UPDATE_TRUE = "true";
    public static final String DB_SCHEMA_UPDATE_FALSE = "false";
    public static final String DB_SCHEMA_UPDATE_CREATE = "create";
    public static final String DB_SCHEMA_UPDATE_DROP_CREATE = "drop-create";
    public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop";

    protected String generateEngineName = GenerateEngines.NAME_DEFAULT;
    protected String databaseTablePrefix = "";
    protected int idBlockSize = 2500;
    protected String databaseType;
    protected String databaseSchemaUpdate = DB_SCHEMA_UPDATE_FALSE;
    protected String jdbcDriver = "org.h2.Driver";
    protected String jdbcUrl = "jdbc:h2:tcp://localhost/~/generate";
    protected String jdbcUsername = "sa";
    protected String jdbcPassword = "";
    protected String dataSourceJndiName;
    protected int jdbcMaxActiveConnections;
    protected int jdbcMaxIdleConnections;
    protected int jdbcMaxCheckoutTime;
    protected int jdbcMaxWaitTime;
    protected boolean jdbcPingEnabled;
    protected String jdbcPingQuery;
    protected int jdbcPingConnectionNotUsedFor;
    protected int jdbcDefaultTransactionIsolationLevel;
    protected DataSource dataSource;
    protected boolean transactionsExternallyManaged;

    protected boolean tablePrefixIsSchema = false;
    protected ClassLoader classLoader;
    protected String databaseWildcardEscapeCharacter;
    protected String databaseCatalog = "";
    protected String databaseSchema;
    protected boolean useClassForNameClassLoading = true;

    protected Clock clock;

    protected GenerateEngineConfiguration() {
    }

    /**
     * 构建代码引擎
     * @return
     */
    public abstract GenerateEngine buildGenerateEngine();

    public static GenerateEngineConfiguration createStandaloneGenerateEngineConfiguration() {
        return new StandaloneGenerateEngineConfiguration();
    }

    // getters and setters
    // //////////////////////////////////////////////////////

}